<?php

namespace App\Libraries\Util;

class ArrayHelper
{
    public static function array_to_object($arr)
    {
        if ('array' != gettype($arr)) {
            return;
        }
        foreach ($arr as $k => $v) {
            if ('array' == gettype($v) || 'object' == gettype($v)) {
                $arr[$k] = (object) ArrayHelper::array_to_object($v);
            }
        }

        return (object) $arr;
    }

    public static function object_to_array($obj)
    {
        $obj = (array) $obj;
        foreach ($obj as $k => $v) {
            if ('resource' == gettype($v)) {
                return;
            }
            if ('object' == gettype($v) || 'array' == gettype($v)) {
                $obj[$k] = (array) ArrayHelper::object_to_array($v);
            }
        }

        return $obj;
    }
}
